package com.chen.palmar.base;

import android.content.Context;
import android.graphics.Point;
import android.support.multidex.MultiDex;
import android.view.WindowManager;

import com.baidu.mapapi.SDKInitializer;
import com.chen.palmar.common.constant.AppConstant;
import com.chen.palmar.common.datasource.DataCenter;
import com.mob.MobApplication;
import com.mob.MobSDK;
import com.orhanobut.logger.LogLevel;
import com.orhanobut.logger.Logger;
import com.primb.androidlibs.utils.Utils;
import com.tencent.bugly.Bugly;
import com.zhy.autolayout.config.AutoLayoutConifg;

/**
 * 应用基类
 */
public class IApplication extends MobApplication {
    public Context applicationContext;
    private String TAG = "---BigManger---";

    @Override
    public void onCreate() {
        super.onCreate();
        applicationContext = this;
        AutoLayoutConifg.getInstance().useDeviceSize();
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        Point point = new Point();
        wm.getDefaultDisplay().getSize(point);
        AppConstant.SCREEN_WIDTH = point.x;
        AppConstant.SCREEN_HEIGHT = point.y;
        Logger.init(TAG).methodCount(3).methodOffset(2).logLevel(LogLevel.FULL);
        //全局异常捕获
        //        CrashHandler crashHandler = CrashHandler.getInstance();
        // 注册crashHandler
        //        crashHandler.init(getApplicationContext());
        /**
         * 工具类初始化
         */
        Utils.init(this);
        /**
         * 数据中心初始化
         */
        DataCenter.init();
        /**
         * 百度地图初始化
         */
        SDKInitializer.initialize(getApplicationContext());

        //bugly验证
        Bugly.init(getApplicationContext(), "e40923b4a8", false);

        //ShareSDK
        MobSDK.init(this);
    }

    public Context getInstance() {
        if (applicationContext == null) {
            applicationContext = this;
        }
        return applicationContext;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
